#ifdef UP_PWM
//*********************************************************************************************/
// Defines for commands used by this userplugin
//*********************************************************************************************/

#define UP_PWM1_KAKUADDRES         251
#define UP_PWM2_KAKUADDRES         252
#define UP_PWM3_KAKUADDRES         253

#define UP_PWM1_COMMAND             21 // senduserevent 21,<dimvalue> or userplugin 21,<dimvalue>
#define UP_PWM2_COMMAND             22 // senduserevent 22,<dimvalue> or userplugin 22,<dimvalue>
#define UP_PWM3_COMMAND             23 // senduserevent 23,<dimvalue> or userplugin 23,<dimvalue>

#define UP_PWM1_PORT                 9 // Arduino Pin Pin D9 or Nodo Shield D9
#define UP_PWM2_PORT                10 // Arduino Pin Pin D10 or Nodo Shield D10
#define UP_PWM3_PORT                11 // Arduino Pin Pin D11 or Nodo Shield D11 (no jumper available!, remove resistor to BC639)

//===================================================================================================================================
// End of user configurable settings, do not change anything below this section!
//===================================================================================================================================

void UserPlugin_PWM_Command(int Par1, int Par2)
{
  if (Par1 == UP_PWM1_COMMAND) analogWrite(UP_PWM1_PORT,Par2);
  if (Par1 == UP_PWM2_COMMAND) analogWrite(UP_PWM2_PORT,Par2);
  if (Par1 == UP_PWM3_COMMAND) analogWrite(UP_PWM3_PORT,Par2);
}

boolean UserPlugin_PWM_Receive(unsigned long Event)
{
  byte Command = (Event >> 16) & 0xff;
  byte Par1 = (Event >> 8) & 0xff;
  byte Par2 = Event & 0xff;

  if (Command = CMD_USEREVENT)
    {
      if (Par1 == UP_PWM1_COMMAND) analogWrite(UP_PWM1_PORT,Par2);
      if (Par1 == UP_PWM2_COMMAND) analogWrite(UP_PWM2_PORT,Par2);
      if (Par1 == UP_PWM3_COMMAND) analogWrite(UP_PWM3_PORT,Par2);
    }

  if (Command = CMD_KAKU_NEW)
   {
     if (Par2 == VALUE_OFF) Par2=0;
     if (Par2 == VALUE_ON) Par2=15;
     if (Par1 == UP_PWM1_KAKUADDRES) analogWrite(UP_PWM1_PORT,Par2*16);
     if (Par1 == UP_PWM2_KAKUADDRES) analogWrite(UP_PWM2_PORT,Par2*16);
     if (Par1 == UP_PWM3_KAKUADDRES) analogWrite(UP_PWM3_PORT,Par2*16);
   } 
  return true;
}
#endif

